package bqds

import (
	"database/sql"
	"fmt"
	"strings"

	tools "gitee.com/boxigg/goutil"
)

func init() {
	tools.InitLogger()
	// var(
	// 	MainIID []string //主力合约ID
	// )
}
func InitPgDB(sf string, db *sql.DB) {
	// read sql statements from file sf(yaml format) and execute them
	sqls := tools.ReadYmlString(sf)
	fmt.Println(sf)
	for k, v := range sqls {
		// fmt.Println(k)
		_, err := db.Exec(v)
		if err != nil {
			fmt.Println(k, err)
		}
	}
	sql := sqls["create_tick_table"]
	sql = strings.Replace(sql, "tick_history", "tick", 1)
	// fmt.Println(sql)
	_, err := db.Exec(sql)
	if err != nil {
		fmt.Println(err)
	}
	sql = sqls["create_bar_table"]
	sql = strings.Replace(sql, "bar_history", "bar", 1)
	db.Exec(sql)

}
